<?php
// $Id: ButtonInput.php 27 2010-11-16 12:49:54Z mjohnson60@gmail.com $


/**
 * Enter description here ...
 * 
 * @author Mark Phillip Johnson
 * @version 1.0
 * @copyright Copyright (c) 2010, markjohnson
 * @license http://www.gnu.org/licenses/gpl.html The GNU General Public License v3.0
 *
 */
class ButtonInput extends FormElement
{
	/**
	 * Enter description here ...
	 * @var string
	 */
	var $button_type = 'button';

	/**
	 * Enter description here ...
	 * @param string $name
	 * @param string $value
	 * @param string $id
	 * @param FormElement $parent
	 * @param array $attributes
	 * @param string $button_type
	 */
	function __construct($name, $value, $id = NULL, $parent = NULL, $attributes = array(), $button_type = 'button')
	{
		if (empty($this->type))
		{
			$this->type = 'button';
		}
		
		$this->button_type = $button_type;
		
		if (is_array($value))
		{
			parent::__construct($value, $name);
		}
		else
		{
			parent::__construct(NULL, $name, $value, $id, $parent, $attributes);
		}
	}

	/* 
	 * @see FormElement::_compile()
	 */
	public function _compile()
	{
		return $this->render();
	}

	/* 
	 * @see FormElement::render()
	 */
	public function render()
	{
		if (empty($this->button_type))
		{
			$this->button_type = 'button';
		}
		
		if (isset($this->attributes['class']))
		{
			$this->attributes['class'] = 'form-' . $this->button_type . ' ' . $this->attributes['class'];
		}
		else
		{
			$this->attributes['class'] = 'form-' . $this->button_type;
		}
		
		return parent::render('<input type="submit" ' . (empty($this->name) ? '' : 'name="' . $this->name . '" ') . ' id="' . $this->id . '" value="' . $this->value . '" ' . (empty($this->attributes) ? '' : attributes($this->attributes)) . " />\n");
	}
}
